package cn.glutnn.oss.config;

/**
 * Author:   msh
 * Date:     2024/12/5 下午2:36
 * Description:
 */

import cn.glutnn.oss.adapter.StorageAdapter;
import cn.glutnn.oss.adapter.AliStorageAdapter;
import cn.glutnn.oss.adapter.MinioStorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RefreshScope
public class StorageConfig {

    @Value("${storage.service.type}")
    private String storageType;

    @Bean
    @RefreshScope
    public StorageAdapter getStorageService() {
        if (storageType.equals("minio")) {
            return new MinioStorageAdapter();
        } else if (storageType.equals("aliyun")) {
            return new AliStorageAdapter();
        } else {
            throw new IllegalArgumentException("未找到对应的文件存储处理器");
        }
    }
}
